package roboticsfmw.core;

public class Timer extends ManagedComponent {

	private Event timeoutEvent;
	private boolean reset;
	private boolean suspend;
	
	public Timer(String name, long pollInterval, Event timeoutEvent) throws IllegalArgumentException {
		super(name, pollInterval, true);
		this.timeoutEvent = timeoutEvent;
		this.reset=true;
		this.suspend=false;
	}
	
	public void suspend() {
		this.suspend=true;
	}
	
	public void resume() {
		this.suspend=false;
	}

	@Override
	public void loop(long i) {
		if (!this.suspend) {
			if (!this.reset) {
				getEventBus().notify(this.timeoutEvent);
			}
			this.reset=false;
		}
	}

	public void reset() {
		this.reset = true;
	}
	
	public boolean isSuspended() {
		return this.suspend;
	}
	
}
